﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DP.Web.UI;
using CRM.BLL;
using CRM.Entity;

namespace CRM.Web.UserManage
{
    public partial class SetSelfPassword : Common.PageBase
    {
        UserLoginInfo _userLoginInfo;
        private T_USER_BLL userBll = new T_USER_BLL();
        protected override void OnInit(EventArgs e)
        {
            base.VerificationRight = false;
            base.OnInit(e);
            _userLoginInfo = UserLoginInfo.GetLoginInfo();
            PageHelper.SetPrePageUrl(this.Page);
            PageHelper.SetGoBackUrl(this.Page, btnCancel, StaticConstant.NotBackUrl);

        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnOK_Click(object sender, EventArgs e)
        {
            if(_userLoginInfo.UserEntity.PASSWORD.Trim() != UserLoginInfo.PasswordEncryption(txtOldPassword.Text.Trim()))
            {
                PageHelper.ShowMessage(this.Page, "原密码错误！");
                return;
            }
            T_USER_Entity userEntity = userBll.GetEntity("USERID", _userLoginInfo.UserEntity.USERID.ToString());
            userEntity.PASSWORD = UserLoginInfo.PasswordEncryption(txtNewPassword.Text.Trim());

            long rel = userBll.Update(userEntity);

            if(rel > 0)
            {
                _userLoginInfo.UserEntity.PASSWORD = userEntity.PASSWORD;
                UserLoginInfo.SetLoginInfo(_userLoginInfo);
                PageHelper.ShowMessage(this.Page, "密码修改成功！");
            }
            else
            {
                PageHelper.ShowMessage(this.Page, "密码修改失败！");
            }

        }




    }
}
